package com.tled.zyf.cookie;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@WebServlet("/cookieDemo1")
public class CookieDemo_01 extends HttpServlet {
	@Override
	protected void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		// 1 创建 cookie
		Cookie cookie1 = new Cookie("msg", "helloword");
		Cookie cookie2 = new Cookie("name", "admin");

		// 设置 cookie 的时间,默认是会话结束 cookie 结束
		// 300 秒后自动消失
		cookie1.setMaxAge(2147483647);
		cookie1.setMaxAge(300);

		// 2 发送 cookie
		response.addCookie(cookie1);
		response.addCookie(cookie2);

	}
}
